# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/3/7 16:26
from selenium.webdriver.common.by import By
from datetime import datetime,timedelta

class  AdminBillLocator:

    # 等待转圈 [class="antd4-spin-dot antd4-spin-dot-spin"]
    wait = (By.CSS_SELECTOR, '[class="antd4-spin-dot antd4-spin-dot-spin"]')

    """
        Bill - Income/Expense
    """
    # bill菜单
    bill_menu = (By.XPATH,'//div[contains(@data-menu-id,"BILLS_PLT")]/span')
    # bill菜单是否打开  class="antd4-menu antd4-menu-sub antd4-menu-inline" 即为打开
    if_open_bill_menu = (By.XPATH,'//div[contains(@data-menu-id,"BILLS_PLT")]/../ul')
    # Income/Expense菜单
    incomeExpense_menu = (By.XPATH,'//div[text()="Income/Expense" and @class="cre-menu-layer-2"]')
    # Income/Expense 页面文本，确认进入页面
    incomeExpense_page_text = (By.XPATH,'(//div[text()="Income/Expense"])[2]')
    # 时间框选项清除按钮
    clear_time= (By.XPATH,'//*[@fill-rule="evenodd"]/..')
    # 时间选择框
    # class="antd4-picker-input antd4-picker-input-active"
    order_time = (By.CSS_SELECTOR, '[class="antd4-picker-input antd4-picker-input-active"]')
    # 选择开始时间title="2023-12-25"
    now = datetime.now()
    one_day_ago = now - timedelta(days=1)
    now_str = now.strftime('%Y-%m-%d')
    now_str1 = now.strftime('%m-%d-%Y')
    content = '[title="' + now_str + '"]'
    order_select_time = (By.CSS_SELECTOR, content)

    now_str_yes = one_day_ago.strftime('%Y-%m-%d')
    content_yes = '[title="' + now_str_yes + '"]'
    order_select_time_yesterday = (By.CSS_SELECTOR, content_yes)
    # 选择特定时间，2023-01-02
    def select_time(str):
        time = '[title="' + str + '"]'
        return (By.CSS_SELECTOR, time)
    # 下载按钮
    click_download = (By.XPATH,'//*[@class="anticon anticon-download"]/..')
    # 下载提示，当未选择时间区间时提示
    download_point_out = (By.XPATH,'//span[text()="Please select start date and end date for export. The export time range cannot exceed 6 months."]')
    # 时间选择框向前选择
    choose_time_before = (By.XPATH,'(//button[@class="antd4-picker-header-prev-btn"])[1]')
    # 页面total总是
    total_text = (By.CSS_SELECTOR,'[class="antd4-pagination-total-text"]')

    """
        Export Records 
    """
    # status状态选择
    status_choose = (By.CSS_SELECTOR,'[class="anticon anticon-filter"]')
    # reset 按钮
    reset_point = (By.XPATH,'//span[text()="Reset"]/..')
    # OK 按钮
    ok_point = (By.XPATH,'//span[text()="OK"]/..')

    # # 下载按钮
    # click_down = (By.XPATH, '//span[@class="anticon anticon-download"]')
    # 进去下载页面提示成功语
    click_down_success_cue = (By.XPATH, '//span[text()="Create asynchronous task successfully"]')
    # 进入Export Records页面
    export_records_success = (By.XPATH, '(//div[text()="Export Records"])[2]')
    # 最新一条下载数据的状态值
    first_down_load_data_status = (By.XPATH, '(//div[@class="cre-table-nowrap"])[1]/../../td[3]//span[text()="Export successful"]')
    # 最新一条下载数据的name
    first_down_load_data_name = (By.XPATH, '(//div[@class="cre-table-nowrap"])[1]')
    # 最新一条数据的下载按钮
    first_download = (By.XPATH, '(//span[text()="Download"])[1]/..')

    """
        Bill - Billing Statement
    """
    # Invoice No.数据项
    bill_body = (By.XPATH,'//thead[1]')
    # billing_statement菜单
    billing_statement_Menu = (By.XPATH,'//div[text()="Billing Statement" and @class="cre-menu-layer-2"]')
    # Income/Expense 页面文本，确认进入页面
    billing_statement_page_text = (By.XPATH, '//span[text()="Billing Statement"]')
    # billing_cycle选择框
    #click_billing_cycle = (By.XPATH,'(//span[@class="antd4-select-selection-item"])[1]')
    click_billing_cycle = (By.XPATH,'//*[text()="Billing Cycle" and @title="Billing Cycle"]/ancestor::*[@class="antd4-row antd4-form-item"]//span[@class="antd4-select-selection-item"]')

    # billing_cycle选择项
    def billing_cycle_item(num):
        content = '(//div[@class="antd4-select-item-option-content" and text()="All"]/../..//div[@class="antd4-select-item-option-content"])['
        content_new = content + num + ']/..'
        print('path地址:',content_new)
        return (By.XPATH,content_new)
    # Settlement Currency 结算货币选择框
    # click_settlement_currency = (By.XPATH,'(//span[@class="antd4-select-selection-item"])[2]')
    click_settlement_currency = (By.XPATH, '//*[text()="Settlement Currency"]/ancestor::div[2]//*[@class="antd4-select-selection-item"]')
    # Settlement Currency 选择项
    def settlement_currency_item(currency):
        content_new = '//div[text()="' + currency + '" and @class="antd4-select-item-option-content"]'
        return (By.XPATH, content_new)
    # Account Email输入框
    input_account_eamil = (By.CSS_SELECTOR,'[id="account"]')
    # search按钮
    click_search = (By.XPATH,'//span[text()="Search"]/..')
    # reset按钮
    click_reset = (By.XPATH,'//span[text()="Reset"]/..')
    # 查询列表Billing Cycle 数据项
    billing_cycle_list = (By.XPATH,'//*[@class="antd4-table-tbody"]//td[@class="antd4-table-cell"][2]/div')
    # 查询列表acccount_emial 数据项
    account_email_list = (By.XPATH,'//*[@class="antd4-table-tbody"]//td[@class="antd4-table-cell"][3]/div')
    # 查询列表status 数据项
    status_list = (By.XPATH,'//*[@class="antd4-table-tbody"]//td[@class="antd4-table-cell"][6]/div//span[@class="antd4-badge-status-text"]')

    # status状态筛选按钮
    click_status = (By.XPATH,'//span[text()="Status"]/..//span[@class="anticon anticon-filter"]')
    # status中的reset按钮
    status_reset = (By.XPATH,'(//span[text()="Reset"]/..)[2]')
    # status中的ok按钮
    status_ok = (By.XPATH,'//span[text()="OK"]/..')
    # 根据状态返回元素地址，然后勾选
    def choose_status_select(status):
        content = '//span[text()="'+ status +'"]/..//span[@class="antd4-checkbox"]'
        return (By.XPATH,content)
    # # Settlement Currency下拉框
    # click_settlement_currency = (By.CSS_SELECTOR,'[id="currency"]')
    # 根据币种名称返回元素定位
    def choose_currency(currency):
        content = '//div[text()="'+ currency +'" and @class="antd4-select-item-option-content"]/..'
        return (By.XPATH,content)
    # total_gross
    #total_gross = (By.XPATH,'//div[text()="Total Gross Amount (ZAR)"]/../div[1]')
    def total_gross(currency):
        content='//div[text()="Total Gross Amount (' + currency +')"]/../div[1]'
        return (By.XPATH, content)
    # Total Paid
    #total_paid =(By.XPATH,'//div[text()="Total Paid Amount (ZAR)"]/../div[1]')
    def total_paid(currency):
        content='//div[text()="Total Paid Amount (' + currency +')"]/../div[1]'
        return (By.XPATH, content)
    # Total Outstanding
    #total_outstanding = (By.XPATH,'//div[text()="Total Outstanding Amount (ZAR)"]/../div[1]')
    def total_outstanding(currency):
        content = '//div[text()="Total Outstanding Amount (' + currency + ')"]/../div[1]'
        return (By.XPATH, content)
    # 下载
    click_down = (By.XPATH,'//span[@class="anticon anticon-download"]/..')
    # 根据提示语和所在位置，定位提示语元素地址  //div[text()="Click to sort descending"]
    def point_out(cue,index='1'):
        content = '(//div[text()="'+cue+'"])['+index+']/..//span'
        print(content)
        return (By.XPATH,content)

    # 根据字段名字来定位字段元素位置
    def amount_by_name(name):
        content = '//span[text()="'+name+'"]'
        return (By.XPATH,content)

    # 根据字段位置，返回字段列表
    def amount_list(index):
        context = '//*[@class="antd4-table-row antd4-table-row-level-0"]/td['+index+']//div[@class="antd4-space-item"]'
        return(By.XPATH,context)


